home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / gnu / gnulib / sipp / libsipp / marble.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-05-03  |  2.4 KB  |  91 lines

  1. /**
  2.  ** sipp - SImple Polygon Processor
  3.  **
  4.  **  A general 3d graphic package
  5.  **
  6.  **  Copyright Equivalent Software HB  1992
  7.  **
  8.  ** This program is free software; you can redistribute it and/or modify
  9.  ** it under the terms of the GNU General Public License as published by
  10.  ** the Free Software Foundation; either version 1, or any later version.
  11.  ** This program is distributed in the hope that it will be useful,
  12.  ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  ** GNU General Public License for more details.
  15.  ** You can receive a copy of the GNU General Public License from the
  16.  ** Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17.  **/
  18.  
  19. /**
  20.  ** marble.c - Marble shader: simulates marble using noise & turbulence
  21.  **/
  22.  
  23. #include <math.h>
  24. #include <stdio.h>
  25.  
  26. #include <sipp.h>
  27. #include <noise.h>
  28. #include <shaders.h>
  29. #include <geometric.h>
  30.  
  31.  
  32. extern bool noise_ready;
  33.  
  34.  
  35. static void
  36. marble(p, color, md)
  37.     Vector *p;
  38.     Color *color;
  39.     Marble_desc *md;
  40. {
  41.     double x, t;
  42.  
  43.     x = p->x + turbulence(p, 7) * 5;
  44.     x = sin(x);
  45.     if (x > -0.1 && x < 0.1) {
  46.         color->red = md->strip.red;
  47.         color->grn = md->strip.grn;
  48.         color->blu = md->strip.blu;
  49.     } else if (x > -0.9 && x < 0.9){
  50.         /* You are not supposed to understand this... */
  51.         t = 7.0 / 6.0 - 1.0 / (6.25 * fabs(x) + 0.375);
  52.         color->red = md->strip.red + t * (md->base.red - md->strip.red);
  53.         color->grn = md->strip.grn + t * (md->base.grn - md->strip.grn);
  54.         color->blu = md->strip.blu + t * (md->base.blu - md->strip.blu);
  55.     } else {
  56.         color->red = md->base.red;         
  57.         color->grn = md->base.grn;
  58.         color->blu = md->base.blu;
  59.     }
  60. }
  61.  
  62.  
  63.  
  64. void
  65. marble_shader(pos, normal, texture, view_vec, lights, md, color, opacity)
  66.     Vector      *pos;
  67.     Vector      *normal;
  68.     Vector      *texture;
  69.     Vector      *view_vec;
  70.     Lightsource *lights;
  71.     Marble_desc *md;
  72.     Color       *color;
  73.     Color       *opacity;
  74. {
  75.     Vector     tmp;
  76.     Surf_desc  surface;
  77.  
  78.     if (!noise_ready) {
  79.         noise_init();
  80.     }
  81.  
  82.     VecScalMul(tmp, md->scale, *texture);
  83.     marble(&tmp, &surface.color, md);
  84.     surface.ambient  = md->ambient;
  85.     surface.specular = md->specular;
  86.     surface.c3       = md->c3;
  87.     surface.opacity = md->opacity;
  88.     basic_shader(pos, normal, texture, view_vec, lights, &surface, 
  89.                  color, opacity);
  90. }
  91.